package com.skiving.cloud.admin.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.mybatisflex.core.paginate.Page;
import com.skiving.cloud.auth.util.UserUtil;
import com.skiving.cloud.common.utils.PageParameter;
import com.skiving.cloud.common.utils.ReturnT;
import com.skiving.cloud.common.utils.UuidUtil;
import com.skiving.cloud.logutils.OperateLogLocal;
import org.noear.solon.annotation.*;
import org.noear.solon.core.util.MimeType;
import com.skiving.cloud.admin.entity.SysDashboardSetting;
import com.skiving.cloud.admin.service.SysDashboardSettingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.time.LocalDateTime;

/**
 * 首页看板设置 控制层。
 *
 * @author skivingcloud
 * @since 2025-03-08
 */
@Controller
@Api("首页看板设置接口")
@Mapping("/sysDashboardSetting")
@Produces(MimeType.APPLICATION_JSON_UTF8_VALUE)
public class SysDashboardSettingController {

    @Inject
    private SysDashboardSettingService sysDashboardSettingService;

    /**
     * 添加首页看板设置。
     *
     * @param sysDashboardSetting 首页看板设置
     * @return {@code true} 添加成功，{@code false} 添加失败
     */
    @Post
    @Mapping("/save")
    @ApiOperation("保存首页看板设置")
    @OperateLogLocal(module="系统管理-首页看板设置", description = "新增首页看板设置")
    @SaCheckPermission("sysDashboardSetting:save")
    public ReturnT<Boolean> save(@Body @ApiParam("首页看板设置") SysDashboardSetting sysDashboardSetting) {
        sysDashboardSetting.setId(UuidUtil.get32UUID());
        sysDashboardSetting.setCreateUser(UserUtil.getCurrentUser().getId());
        sysDashboardSetting.setCreateTime(LocalDateTime.now());
        sysDashboardSetting.setTenantId(UserUtil.getCurrentUser().getTenantId());
        return ReturnT.ok(sysDashboardSettingService.save(sysDashboardSetting));
    }

    /**
     * 根据主键删除首页看板设置。
     *
     * @param id 主键
     * @return {@code true} 删除成功，{@code false} 删除失败
     */
    @Get
    @Mapping("/remove/{id}")
    @ApiOperation("根据主键首页看板设置")
    @OperateLogLocal(module="系统管理-首页看板设置", description = "删除首页看板设置")
    @SaCheckPermission("sysDashboardSetting:remove")
    public ReturnT<Boolean> remove(@Path @ApiParam("首页看板设置主键") String id) {
        return ReturnT.ok(sysDashboardSettingService.removeById(id));
    }

    /**
     * 根据主键更新首页看板设置。
     *
     * @param sysDashboardSetting 首页看板设置
     * @return {@code true} 更新成功，{@code false} 更新失败
     */
    @Post
    @Mapping("/update")
    @ApiOperation("根据主键更新首页看板设置")
    @OperateLogLocal(module="系统管理-首页看板设置", description = "修改首页看板设置")
    @SaCheckPermission("sysDashboardSetting:update")
    public ReturnT<Boolean> update(@Body @ApiParam("首页看板设置主键") SysDashboardSetting sysDashboardSetting) {
        sysDashboardSetting.setModUser(UserUtil.getCurrentUser().getId());
        sysDashboardSetting.setModTime(LocalDateTime.now());
        return ReturnT.ok(sysDashboardSettingService.updateById(sysDashboardSetting));
    }

    /**
     * 根据首页看板设置主键获取详细信息。
     *
     * @param id 首页看板设置主键
     * @return 首页看板设置详情
     */
    @Get
    @Mapping("/getInfo/{id}")
    @ApiOperation("根据主键获取首页看板设置")
    public ReturnT<SysDashboardSetting> getInfo(@Path @ApiParam("首页看板设置主键") String id) {
        return ReturnT.ok(sysDashboardSettingService.getById(id));
    }

    /**
     * 分页查询首页看板设置。
     *
     * @param parameter 分页对象
     * @return 分页对象
     */
    @Post
    @Mapping("/page")
    @ApiOperation("分页查询首页看板设置")
    @SaCheckPermission("sysDashboardSetting:page")
    public ReturnT<Page<SysDashboardSetting>> page(@Body @ApiParam("分页信息") PageParameter<SysDashboardSetting> parameter) {
        return ReturnT.ok(sysDashboardSettingService.queryByPage(parameter));
    }

}
